from appium import webdriver
import os,time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions  as Ec
from  time import sleep
class Base():
    def __init__(self):
        os.system('adb root')
        cap={
            "platformName": "Android",
            "deviceName": "emulator-5554",
            "noReset": True,
            "appPackage": "cn.xuexi.android",
            "appActivity": "com.alibaba.android.rimet.biz.home.activity.HomeActivity"
        }
        self.devices=webdriver.Remote('http://127.0.0.1:4723/wd/hub',cap)
        self.devices.implicitly_wait(25)
        sleep(15)
    def find_ele(self,loc):
        if type(loc)==str:
           return self.devices.find_element_by_android_uiautomator(loc)
        else:
            return self.devices.find_element(*loc)
    def find_wait_ele(self,loc):
        return WebDriverWait(self.drive,15).until(Ec.presence_of_element_located(loc))

    def get_key_value(self,loc,key):
        ele = self.find_ele(loc)
        return ele.get_attribute(key)

    def jieping(self,filename):

        t = time.strftime('Y%m%D%H%M%S%',time.localtime())
        self.drive.save_screenshot(t+filename)
    def qingqiao(self,x,y):
        self.devices.tap([(x,y)],500)
    def huadong(self,x,y,x1,y1):
        self.devices.swipe(x,y,x1,y1,500)
    def tuic(self):
        self.devices.quit()